<template>
    <div>
        <h1>科室显示页面</h1>
        科室名称: <input type="text" v-model="page.name"> &nbsp; &nbsp; &nbsp;
        创建时间: <input type="date" v-model="page.Timeindex">- <input type="date" v-model="page.Timeend">
        &nbsp; &nbsp; &nbsp;
        <input type="button" value="查询" @click="Show" class="btn - btn-success">   
        &nbsp; &nbsp; &nbsp;
        <input type="button" value="清空" @click="Qingkong" class="btn - btn-success">     &nbsp; &nbsp; &nbsp;
        <a href="/KeHomeAdd">新增科室</a> &nbsp;&nbsp;&nbsp;
        <a href="/Show">返回首页</a> &nbsp;&nbsp;&nbsp;
        <a href="https://localhost:7036/api/KeHome/Exil">导出科室信息</a>
        <table class="table">
                    <thead>
                        <tr>
                            <td>编号</td>
                            <td>科室名称</td>
                            <td>科室人数</td>
                            <td>科室描述</td>
                            <td>创建日期</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="a in data">
                            <td>{{a.kid}}</td>
                            <td>{{a.keName}}</td>
                            <td>{{a.kePeople}}</td>
                            <td>{{a.keMiaoS}}</td>
                            <td>{{a.keTimes}}</td>
                            <td>
                                <input type="button" value="删除" @click="DeleteKe(a.kid)" class="btn - btn-success">
                                <input type="button" value="修改" @click="UpdateKe(a.kid)" class="btn - btn-success">
                            </td>
                        </tr>
                    </tbody>
            </table>
    </div>
</template>

<script setup lang="ts">
import {onMounted, ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'
const router = useRouter();

onMounted(()=>{
    Show()
})

const Qingkong=()=>{
    page.value.name='',
    page.value.Timeend='',
    page.value.Timeindex=''
}


const data = ref([
    {
          "kid": 4,
    "keName": "",
    "kePeople": "",
    "keMiaoS": "",
    "keTimes": "2025-05-19T00:00:00",
    "keLuoji": true
    }
])
const page = ref({
    name:'',
    Timeindex:'',
    Timeend:''
});

const Show=()=>{
    axios.get("/api/KeHome/ShowKeHome",{params:page.value}).then(res=>{
           data.value=res.data;
           
    })
}
const DeleteKe=(mid:any)=>{
    if(!confirm("确认删除吗?"))
{
    return;
}
    axios.get("/api/KeHome/DeleteKeHome",{params:{id:mid}}).then(res=>{
           if(res.data>0)
           {
                alert('删除成功');
                Show();
           }
           else{
            alert('删除失败');
           }
           
    })
}


const UpdateKe=(mid:any)=>{
    router.push({path:'/UpdateKe',query:{id:mid}})
}


</script>

<style scoped>

</style>